import jieba
from matplotlib import pyplot as plt
from wordcloud import WordCloud
import numpy as np
from PIL import Image
from utils.query import querys

def get_img(targetImageSrc,resImageSrc):
    data = querys('select type from fooddata',[],'select')
    text = ''
    for i in data:
        if i[0] != '':
            tarArr = i
            for j in tarArr:
                text += j

    data_cut = jieba.cut(text,cut_all=False)
    strting = ' '.join(data_cut)

    img = Image.open(targetImageSrc)
    img_arr = np.array(img)
    wc = WordCloud(
        background_color='#fff',
        font_path='STHUPO.TTF',
        mask=img_arr
    )
    wc.generate_from_text(strting)
    fig = plt.figure(1)
    plt.imshow(wc)
    plt.axis('off')
    plt.savefig(resImageSrc,dpi=800,bbox_inches='tight',pad_inches=-0.1)

get_img('./static/assets/love.jpg',"./static/assets/cloudImg/cloudType")